{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "post\n",
      "ant09 :\n",
      "\t mota 0.97\n",
      "\t motp 0.77\n",
      "COMBINED :\n",
      "\t mota 0.97\n",
      "\t motp 0.77\n",
      "\n",
      "main\n",
      "ant09 :\n",
      "\t mota 0.94\n",
      "\t motp 0.77\n",
      "COMBINED :\n",
      "\t mota 0.94\n",
      "\t motp 0.77\n"
     ]
    }
   ],
   "source": [
    "import  os \n",
    "from os.path import join, isdir, isfile, exists\n",
    "from os import makedirs\n",
    "\n",
    "import cv2\n",
    "from glob import glob\n",
    "\n",
    "import json\n",
    "\n",
    "\n",
    "import numpy as np \n",
    "\n",
    "\n",
    "\n",
    "class ResultAnalysor:\n",
    "\n",
    "\n",
    "    def __init__(self,path,test_name = \"beedance_test\"):\n",
    "\n",
    "        self.path = path \n",
    "        \n",
    "        main_path = join(path,test_name)\n",
    "        post_path = join(path,test_name + '_post')\n",
    "\n",
    "\n",
    "        def get_res(path):\n",
    "\n",
    "            quantitative_results = np.loadtxt(join(\n",
    "                path,\n",
    "                \"pedestrian_summary.txt\"\n",
    "            ),np.str0,delimiter = '\\n')\n",
    "\n",
    "            quantitative_results = [line.split(' ') for line in quantitative_results]\n",
    "\n",
    "            quantitative_results_map = {}\n",
    "            for k,v in zip(quantitative_results[0],quantitative_results[1]):\n",
    "                quantitative_results_map[k] = v\n",
    "\n",
    "            del quantitative_results\n",
    "\n",
    "\n",
    "            detailed_data = np.loadtxt(join(path,'pedestrian_detailed.csv'),np.str0,delimiter = ',')\n",
    "            mota_idx = np.where(detailed_data[0] == 'MOTA')[0]\n",
    "            motp_idx = np.where(detailed_data[0] == 'MOTP')[0]\n",
    "            quantitative_results_seqs = {}\n",
    "            for seq in range(1,detailed_data.shape[0]):\n",
    "                seq_name = detailed_data[seq,0]\n",
    "                mota  = detailed_data[seq,mota_idx]\n",
    "                motp  = detailed_data[seq,motp_idx]\n",
    "                quantitative_results_seqs[seq_name] = {'mota':mota,\"motp\":motp}\n",
    "                # print(seq_name,'mota:',mota,\"motp:\", motp)\n",
    "                \n",
    "            \n",
    "\n",
    "\n",
    "            return  quantitative_results_map,quantitative_results_seqs\n",
    "        quantitative_results_map, quantitative_results_seqs = get_res(post_path)\n",
    "        main_quantitative_results_map, main_quantitative_results_seqs= get_res(main_path)\n",
    "\n",
    "        self.quantitative_results_map = quantitative_results_map\n",
    "        self.quantitative_results_seqs = quantitative_results_seqs\n",
    "        self.main_quantitative_results_map = main_quantitative_results_map\n",
    "        self.main_quantitative_results_seqs = main_quantitative_results_seqs\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "results_path = \"/data/xusc/exp/topictrack-bee/results/trackers/antmove-val/\"\n",
    "analysor = ResultAnalysor(results_path,test_name='antmove_test')\n",
    "\n",
    "\n",
    "# results_path = \"/data/xusc/exp/topictrack-bee/results/trackers/beedance-val\"\n",
    "# analysor = ResultAnalysor(results_path)\n",
    "\n",
    "\n",
    "\n",
    "# analysor.quantitative_results_map\n",
    "# analysor.main_quantitative_results_map\n",
    "# analysor.quantitative_results_seqs\n",
    "\n",
    "\n",
    "def printer(__dict):\n",
    "    for k,v in __dict.items():        \n",
    "        print(k,\":\")\n",
    "        for kk,vv in v.items():\n",
    "            print(\"\\t\",kk,\"%.2f\"%(float(vv[0])))\n",
    "print(\"post\")\n",
    "printer(analysor.quantitative_results_seqs)\n",
    "\n",
    "print(\"\\nmain\")\n",
    "printer(analysor.main_quantitative_results_seqs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "ant03 :\n",
      "\t mota 0.40\n",
      "\t motp 0.64\n",
      "ant04 :\n",
      "\t mota 0.55\n",
      "\t motp 0.69\n",
      "COMBINED :\n",
      "\t mota 0.47\n",
      "\t motp 0.66\n"
     ]
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'HOTA': '0.34577',\n",
       " 'DetA': '0.23488',\n",
       " 'AssA': '0.57071',\n",
       " 'DetRe': '0.23641',\n",
       " 'DetPr': '19.231',\n",
       " 'AssRe': '0.57271',\n",
       " 'AssPr': '51.407',\n",
       " 'LocA': '66.072',\n",
       " 'RHOTA': '0.34702',\n",
       " 'HOTA(0)': '0.9137',\n",
       " 'LocA(0)': '27.762',\n",
       " 'HOTALocA(0)': '0.25366',\n",
       " 'MOTA': '-0.99291',\n",
       " 'MOTP': '55.781',\n",
       " 'MODA': '-0.94563',\n",
       " 'CLR_Re': '0.14184',\n",
       " 'CLR_Pr': '11.538',\n",
       " 'MTR': '0',\n",
       " 'PTR': '0',\n",
       " 'MLR': '100',\n",
       " 'CLR_TP': '3',\n",
       " 'CLR_FN': '2112',\n",
       " 'CLR_FP': '23',\n",
       " 'IDSW': '1',\n",
       " 'MT': '0',\n",
       " 'PT': '0',\n",
       " 'ML': '16',\n",
       " 'Frag': '0',\n",
       " 'sMOTA': '-1.0556',\n",
       " 'IDF1': '0.18683',\n",
       " 'IDR': '0.094563',\n",
       " 'IDP': '7.6923',\n",
       " 'IDTP': '2',\n",
       " 'IDFN': '2113',\n",
       " 'IDFP': '24',\n",
       " 'Dets': '26',\n",
       " 'GT_Dets': '2115',\n",
       " 'IDs': '18',\n",
       " 'GT_IDs': '16'}"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "yang_real",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
